using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using Caliburn.Micro;
using OrbitOne.CRMLyncInfoDashboard.CRM.OData;
using OrbitOne.CRMLyncInfoDashboard.Lync;

namespace OrbitOne.CRMLyncInfoDashboard.Shell
{

    [Export(typeof(IShellViewModel))]
    public class ShellViewModel : Conductor<IScreen> /*PropertyChangedBase*/, IShellViewModel
    {
        private readonly IEnumerable<IScreen> m_screens;

        public T GetScreen<T>()
        {
            return (T)m_screens.Single(s => typeof(T).IsAssignableFrom(s.GetType()));
        }

        public ISummaryViewModel SummaryScreen
        {
            get { return GetScreen<ISummaryViewModel>(); }
        }

        public IDetailViewModel DetailScreen
        {
            get { return GetScreen<IDetailViewModel>(); }
        }
        
        [ImportingConstructor]
        public ShellViewModel([ImportMany]IEnumerable<IScreen> screens)
        {
            m_screens = screens;
            ShowSummaryView();
        }

        public void ShowSummaryView()
        {
            ActivateItem((IScreen)SummaryScreen);
        }

        public void ShowDetailView()
        {
            ActivateItem((IScreen)DetailScreen);
        }

        public void ShowDetailView(IEntityModel entityModel, Endpoint[] endpoints)
        {
            var entityType = (EntityModelTypes)Enum.Parse(typeof(EntityModelTypes), entityModel.GetType().Name, true);

            DetailScreen.EntityModelType = entityType;
            DetailScreen.EntityModel = entityModel;
            DetailScreen.Endpoints = endpoints;
            ActivateItem((IScreen)DetailScreen);
        }

        
    }
}
